package com.mxf.code.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;


/**
 * @author 性别
 */

@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Gender {

    /**
     * 男士
     */
    MALE(1, "男士"),

    /**
     * 女士
     */
    FEMALE(2, "女士");

    /**
     * 编码
     */

    private final Integer code;
    /**
     * 注释
     */
    //@JsonValue
    private final String desc;

    Gender(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static Gender fromString(String value) {
        if (value == null) {
            return null;
        }
        for (Gender gender : Gender.values()) {
            if (gender.name().equalsIgnoreCase(value)) {
                return gender;
            }
        }
        return null;
    }

    public static Gender fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (Gender gender : Gender.values()) {
            if (gender.getCode().equals(code)) {
                return gender;
            }
        }
        throw new IllegalArgumentException("Invalid code: " + code);
    }
}
